package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;

import com.dongdongshop.pojo.TbSpecification;
import com.dongdongshop.pojo.TbSpecificationOption;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.service.TempLateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName TempLateController
 * @Author RC
 * @date 2020.12.10 21:50
 */
@Controller
@RequestMapping("template")
public class TempLateController {

    @Reference(timeout = 100000,check = false)
    private TempLateService tempLateService;
    @Reference(timeout = 100000,check = false)
    private BrandService brandService;

    private static final Logger logger = LoggerFactory.getLogger(TempLateController.class);


    @RequestMapping("getTempLateList")
    @ResponseBody
    public DataResult getTempLateList() {
        try {
            logger.info("进入模板查询方法");
            List<TbTypeTemplate> tempLateList = tempLateService.getTempLateList();
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(tempLateList);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }

    @RequestMapping("saveTemplate")
    @ResponseBody
    public DataResult saveTemplate(TbTypeTemplate tbTypeTemplate) {
        //保存  数据有空值 数据库保存异常 ,业务方面导致的没有添加成功 falise
        //可以使用map
        try {
            logger.info("进入增加模板方法");
            tempLateService.saveTemplate(tbTypeTemplate);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        } catch (Exception e) {
            logger.info("增加失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }

    @RequestMapping("toUpdateTemplate/{id}")
    @ResponseBody
    public DataResult toTemplate(@PathVariable("id")Long id ){
        try {
            logger.info("进入回显方法");
            TbTypeTemplate template = tempLateService.getBrandById(id);

            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(template);
        }catch (Exception e){
            logger.info("回显失败 ",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    @RequestMapping("deleteBatchTemplate/{ids}")
    @ResponseBody
    public DataResult deleteBatchTemplate(@PathVariable("ids")Integer[] ids){
        try{
            logger.info("进入删除方法");
            tempLateService.deleteBatchTemplate(ids);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        }catch (Exception e){
            logger.info("删除失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    @RequestMapping("updateTemplate")
    @ResponseBody
    public DataResult updateTemplate(TbTypeTemplate tbTypeTemplate) {
        //保存  数据有空值 数据库保存异常 ,业务方面导致的没有添加成功 falise
        //可以使用map
        try {
            logger.info("进入增加模板方法");
            tempLateService.updateTemplate(tbTypeTemplate);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        } catch (Exception e) {
            logger.info("增加失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
}
